from langgraph.graph import StateGraph

def node_a(state):
    return {"x":state["x"]+1}

def node_b(state):
    return {"x":state["x"]-2}

def node_c(state):
    return {"x":state["x"]+1}

def routing_function(state):
    if state["x"] == 10:
        return "node_b"
    else:
        return "node_c"

builder = StateGraph(dict)

builder.add_node("node_a",node_a)
builder.add_node("node_b",node_b)
builder.add_node("node_c",node_c)

builder.set_entry_point("node_a")

builder.add_conditional_edges("node_a",routing_function)

graph = builder.compile()
resp = graph.invoke({"x":9})
print(resp)